package com.aspose.cells;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Random;

class zaax {
   static zfk a = new zfk();
   static zfg b = new zfg();
   zbti c = new zbti();
   zbtg d = new zbtg();
   zbth e = new zbth();
   public Workbook f;
   public WorksheetCollection g;
   public zur h;
   public int i;
   public boolean j;
   public zxx k;
   public boolean l;
   public boolean m;
   public double n;
   public DateTime o;
   public boolean p;
   public int q;
   public boolean r;
   public int s;
   public Random t = new Random();
   public boolean u = false;
   public int v = 255;
   public boolean w = false;
   public int x = 1;
   public HashMap y;
   public HashMap z;
   public HashMap A;
   public HashMap B;
   public HashMap C;
   public HashMap D;
   public HashMap E;
   public HashMap F;
   public boolean G = false;
   public long[] H;
   public int I;
   public int J;
   public zaoe[] K;
   public int[] L;
   public int M;
   public long[] N;
   public int O;
   public zjt P;
   public CalculationOptions Q;
   private int R;

   public zaax(Workbook var1, int var2, CalculationOptions var3) {
      this.f = var1;
      this.Q = var3;
      this.g = var1.getWorksheets();
      WorkbookSettings var4 = var1.getSettings();
      this.i = this.g.u();
      this.h = this.j();
      this.j = !var1.k();
      this.k = var4.e();
      this.l = var4.getDate1904();
      this.m = var4.getPrecisionAsDisplayed();
      this.o = CellsHelper.getDateTimeFromDouble(0.0D, this.l);
      this.n = CellsHelper.getDoubleFromDateTime(DateTime.b, this.l);
      this.q = var4.getMaxIteration();
      this.p = var4.getIteration() && this.q > 0;
      this.s = var2;
      this.r = var4.getCreateCalcChain() && var2 == 1;
      if (var3 != null) {
         this.P = new zjt(200);
         this.R = var3.d > -1 ? var3.d : var4.getCalcStackSize();
         this.H = new long[this.R << 1];
         this.I = 0;
         this.J = this.R;
         this.K = new zaoe[8];
         this.L = new int[this.K.length];
         this.M = 0;
         if (this.r) {
            this.N = new long[16];
            this.O = 0;
         }
      }

   }

   void a(int var1) {
      if (this.B != null && this.B.size() >= 1) {
         long[] var2 = new long[this.B.size()];
         int var3 = 0;

         for(Iterator var6 = this.B.keySet().iterator(); var6.hasNext(); var2[var3++] = (Long)var6.next()) {
            ;
         }

         for(var3 = 0; var3 < var2.length; ++var3) {
            long var4 = var2[var3];
            int var7 = (int)(var4 & 255L);
            if (var7 == var1 || this.a((zej)this.B.get(var4), var7)) {
               this.B.remove(var4);
            }
         }

      }
   }

   private boolean a(zej var1, int var2) {
      return this.g.get(var2).getCells().a(var1.a, var1.a.StartRow, var1.a.StartColumn, new zgm(true, true, false, false), false, true) == null;
   }

   void a(Object var1, zej var2) {
      if (this.B == null) {
         this.B = new HashMap();
      }

      this.B.put(var1, var2);
   }

   zej a(Object var1) {
      return this.B == null ? null : (zej)this.B.get(var1);
   }

   void b(Object var1) {
      if (this.B != null) {
         this.B.remove(var1);
      }
   }

   Object a(String var1) {
      Object var2 = null;
      if (this.C != null) {
         var2 = this.C.get(var1);
         if (var2 != null) {
            return var2;
         }
      }

      var2 = zbpt.a(var1, true);
      if (var2 == null) {
         return null;
      } else {
         if (this.C == null) {
            this.C = new HashMap();
         }

         this.C.put(var1, var2);
         return var2;
      }
   }

   void a() {
      this.J += this.R;
      if (this.J > this.H.length) {
         long[] var1 = new long[this.H.length + this.R];
         System.arraycopy(this.H, 0, var1, 0, this.I);
         this.H = var1;
      }

   }

   void b() {
      this.J = this.R;
   }

   int b(int var1) {
      return Math.min(this.R, this.J - var1);
   }

   void c(int var1) {
      this.J = this.I + var1;
      if (this.J > this.H.length) {
         long[] var2 = new long[this.H.length + this.R];
         System.arraycopy(this.H, 0, var2, 0, this.I);
         this.H = var2;
      }

   }

   void a(long var1) {
      if (this.Q.i.e) {
         this.Q.i.b.append('|');
      }

      this.H[this.I] = var1;
      ++this.I;
      if (this.I == this.J) {
         throw a;
      }
   }

   long c() {
      --this.I;
      if (this.Q.i.e) {
         this.Q.i.b.setLength(this.I);
      }

      return this.H[this.I];
   }

   void a(zaoe var1) {
      if (this.M == this.K.length) {
         zaoe[] var2 = new zaoe[this.K.length << 1];
         System.arraycopy(this.K, 0, var2, 0, this.K.length);
         this.K = var2;
         int[] var3 = new int[var2.length];
         System.arraycopy(this.L, 0, var3, 0, this.L.length);
         this.L = var3;
      }

      var1.b = true;
      this.K[this.M] = var1;
      this.L[this.M] = this.I;
      ++this.M;
   }

   zaoe d() {
      zaoe var1 = this.K[--this.M];
      var1.b = false;
      return var1;
   }

   void a(zyi var1) {
      if (!this.p || !this.w || this.I > this.x) {
         b.a = var1;
         throw b;
      }
   }

   void e() {
      do {
         this.H[this.x - 1] = this.H[this.x];
         ++this.x;
      } while(this.x != this.I);

      --this.I;
   }

   void d(int var1) {
      if (this.I != var1 + 1) {
         long[] var2 = new long[this.I - var1];
         long var3 = this.H[var1];
         int var7 = zyi.a(var3);
         Worksheet var8 = this.g.get(var7);
         zyi var9 = var8.getCells().b.a(zyi.b(var3));
         var2[0] = Cell.a(zyi.a(var3), var9.e, var9.f);

         for(int var11 = var1 + 1; var11 < this.I; ++var11) {
            var3 = this.H[var11];
            var7 = zyi.a(var3);
            var8 = this.g.get(var7);
            var9 = var8.getCells().b.a(zyi.b(var3));
            long var5 = Cell.a(zyi.a(var3), var9.e, var9.f);
            int var10 = com.aspose.cells.b.a.za.a(var2, 0, var11 - var1, var5);
            if (var10 < 0) {
               var10 = -var10 - 1;
            }

            if (var10 < var11 - var1) {
               System.arraycopy(var2, var10, var2, var10 + 1, var11 - var1 - var10);
               var2[var10] = var5;
               var10 += var1;
               System.arraycopy(this.H, var10, this.H, var10 + 1, var11 - var10);
               this.H[var10] = var3;
            } else {
               var2[var10] = var5;
            }
         }

      }
   }

   void e(int var1) {
      int var2 = this.I - var1;
      if (this.r && this.N.length < this.O + var2) {
         long[] var3 = new long[Math.max(this.N.length << 1, this.N.length + var2)];
         System.arraycopy(this.N, 0, var3, 0, this.O);
         this.N = var3;
      }

      while(var1 < this.I) {
         long var5 = this.H[var1];
         if (this.r) {
            this.N[this.O] = var5;
            ++this.O;
         }

         this.g.get(zyi.a(var5)).getCells().b.a(zyi.b(var5)).a((byte)2);
         ++var1;
      }

      this.I -= var2;
   }

   void f() {
      for(int var3 = 0; var3 < this.O; ++var3) {
         long var1 = this.N[var3];
         this.g.get(zyi.a(var1)).getCells().b.a(zyi.b(var1)).a((byte)0);
      }

   }

   public int g() {
      return this.j ? '\uffff' : 1048575;
   }

   public int h() {
      return this.j ? 255 : 16383;
   }

   public boolean i() {
      switch(this.v) {
      case 6:
      case 7:
      case 8:
      case 9:
         return true;
      default:
         return false;
      }
   }

   public int f(int var1) {
      return (Integer)this.z.get(var1);
   }

   zafy b(String var1) {
      zafy var2 = null;
      if (this.y != null) {
         var2 = (zafy)this.y.get(var1);
      }

      if (var2 != null) {
         return var2;
      } else {
         if (this.k.m() != null) {
            var2 = (zafy)this.k.m().get(var1);
            if (var2 != null) {
               return var2;
            }
         }

         var2 = this.k.b(var1, false);
         if (this.y == null) {
            this.y = new HashMap();
         }

         this.y.put(var1, var2);
         return var2;
      }
   }

   zxz a(String var1, int var2, Object var3) {
      return this.b(var1).a(this.k.j(), var2, var3);
   }

   private zur j() {
      zbqf var1 = this.g.v();

      for(int var2 = var1.getCount() - 1; var2 > -1; --var2) {
         if (var1.a(var2).a() == 5) {
            zus var4 = this.g.q();
            int var5 = var4.e(var2, 65534, 65534);
            zur var3;
            if (var5 > -1) {
               var3 = var4.b(var5);
            } else {
               var3 = new zur(var2, 65534, 65534);
            }

            this.D = new HashMap();
            this.D.put((long)var2 << 32 | 4294901758L, this.h);
            return var3;
         }
      }

      return null;
   }
}
